'use strict';
let Response = require('../../../model/Response');
let RestifyProxy = require('../../../util/RestifyProxy');
let CustomPageBean = require('../../../model/CustomPageBean');
let permissionService = require('../../../service/system/permissionService');
let logger = require('../../../util/LoggerUtil').logger('permissionController.js');

/**
 * 系统设置——功能权限管理——页面
 */
module.exports.functionPage = function () {
    let response = new Response();
    response.render('back/system/function-permission/function-permission');
    this.resolve(response);
};
/**
 * 系统设置——功能权限管理——数据
 */
module.exports.functionList  = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await permissionService.functionList(this, params);
        let pageBean = new CustomPageBean(result);
        response.send(pageBean);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 系统设置——功能权限管理——右侧树菜单
 */
module.exports.functionTree  = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await permissionService.functionTree(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 系统设置——功能权限管理——分配权限按钮
 */
module.exports.functionConfirm = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await permissionService.functionConfirm(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 系统设置——数据权限管理——页面
 */
module.exports.dataPage = function () {
    let response = new Response();
    response.render('back/system/data-permission/data-permission');
    this.resolve(response);
};
/**
 * 系统设置——数据权限管理——数据
 */
module.exports.dataList  = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await permissionService.dataList(this, params);
        let pageBean = new CustomPageBean(result);
        response.send(pageBean);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 系统设置——数据权限管理——右侧树菜单
 */
module.exports.dataTree  = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await permissionService.dataTree(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 系统设置——操作日志——清理按钮
 */
module.exports.dataConfirm = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await permissionService.dataConfirm(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};